﻿Jxstar.currentPage = function() {
	var config = {param:{},initpage:function(page, define){},eventcfg:{}};
	
	var changetypeData = Jxstar.findComboData('changetype');
	var auditData = Jxstar.findComboData('audit');
	var moneytypeData = Jxstar.findComboData('moneytype');
	var plantypeData = Jxstar.findComboData('plantype');
	var items = [{
		height: '97%',
		width: '97%',
		border: false,
		layout: 'form',
		style: 'padding:10px;',
		items: [{
			anchor:'100%',
			border: false,
			layout:'column',
			autoHeight:true,
			items:[{
				border:false,
				columnWidth:0.495,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'trigger', fieldLabel:'计划编号', name:'money_change__plan_code',
						anchor:'100%', triggerClass:'x-form-search-trigger',
						maxLength:20, allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', editable:false,
						onTriggerClick: function() {
							var selcfg = {pageType:'combogrid', nodeId:'money_select', layoutPage:'/public/layout/layout_tree.js', sourceField:'money_plan.plan_code;plan_id;plan_money;year_money;plan_money;year_money', targetField:'money_change.plan_code;plan_id;after_money;after_yearmoney;before_money;before_yearmoney', whereSql:"plan_status in ('41', '42') and not exists (select * from money_change where auditing = '0' and money_change.plan_id = money_plan.plan_id)", whereValue:'', whereType:'', isSame:'1', isShowData:'1', isMoreSelect:'0',isReadonly:'1',fieldName:'money_change.plan_code'};
							JxSelect.createSelectWin(selcfg, this, 'node_money_chg_form');
						}},
					{xtype:'textfield', fieldLabel:'项目名称', name:'money_change__plan_name', readOnly:true, anchor:'100%', maxLength:50},
					{xtype:'numberfield', decimalPrecision:2, fieldLabel:'数量', name:'money_plan__plan_num', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'单价(万元)', name:'money_plan__plan_price', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'textfield', fieldLabel:'预算年度', name:'money_plan__plan_year', readOnly:true, anchor:'100%', maxLength:100},
					{xtype:'textfield', fieldLabel:'申报人', name:'money_plan__plan_user', readOnly:true, anchor:'100%', maxLength:100},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'调整前总投资(万元)', name:'money_change__before_money', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'调整后总投资(万元)', name:'money_change__after_money', defaultval:'0', anchor:'100%', maxLength:12},
					{xtype:'textfield', fieldLabel:'调概批复文号', name:'money_change__chg_fileno', anchor:'100%', maxLength:100},
					{xtype:'textfield', fieldLabel:'调整申请人', name:'money_change__change_user', defaultval:'fun_getUserName()', readOnly:true, anchor:'100%', maxLength:20},
					{xtype:'combo', fieldLabel:'调整类型', name:'money_change__change_type', defaultval:'0',
						anchor:'100%', editable:false, allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*',
						store: new Ext.data.SimpleStore({
							fields:['value','text'],
							data: changetypeData
						}),
						emptyText: jx.star.select,
						mode: 'local',
						triggerAction: 'all',
						valueField: 'value',
						displayField: 'text',
						value: changetypeData[0][0]},
					{xtype:'hidden', fieldLabel:'申报部门ID', name:'money_change__dept_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'申报人ID', name:'money_plan__plan_userid', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'投资计划ID', name:'money_change__plan_id', anchor:'100%'}
				]
			},{
				border:false,
				columnWidth:0.495,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'combo', fieldLabel:'记录状态', name:'money_change__auditing', defaultval:'0',
						anchor:'100%', readOnly:true, editable:false,
						store: new Ext.data.SimpleStore({
							fields:['value','text'],
							data: auditData
						}),
						emptyText: jx.star.select,
						mode: 'local',
						triggerAction: 'all',
						valueField: 'value',
						displayField: 'text',
						value: auditData[0][0]},
					{xtype:'combo', fieldLabel:'项目类别', name:'money_change__money_type',
						anchor:'100%', readOnly:true, editable:false,
						store: new Ext.data.SimpleStore({
							fields:['value','text'],
							data: moneytypeData
						}),
						emptyText: jx.star.select,
						mode: 'local',
						triggerAction: 'all',
						valueField: 'value',
						displayField: 'text',
						value: moneytypeData[0][0]},
					{xtype:'textfield', fieldLabel:'单位', name:'money_plan__plan_unit', readOnly:true, anchor:'100%', maxLength:100},
					{xtype:'textfield', fieldLabel:'预计实施时间', name:'money_plan__plan_period', readOnly:true, anchor:'100%', maxLength:100},
					{xtype:'datefield', fieldLabel:'申报日期', name:'money_plan__plan_date', format:'Y-m-d', anchor:'100%', readOnly:true},
					{xtype:'textfield', fieldLabel:'申报部门', name:'money_change__dept_name', readOnly:true, anchor:'100%', maxLength:50},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'调整前当年投资(万元)', name:'money_change__before_yearmoney', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'调整后当年投资(万元)', name:'money_change__after_yearmoney', defaultval:'0', anchor:'100%', maxLength:12},
					{xtype:'textfield', fieldLabel:'调概批文名称', name:'money_change__chg_filename', anchor:'100%', maxLength:150},
					{xtype:'datefield', fieldLabel:'调整申请日期', name:'money_change__apply_date', defaultval:'fun_getToday()', format:'Y-m-d', anchor:'100%'},
					{xtype:'combo', fieldLabel:'计划类型', name:'money_change__plan_type',
						anchor:'100%', readOnly:true, editable:false,
						store: new Ext.data.SimpleStore({
							fields:['value','text'],
							data: plantypeData
						}),
						emptyText: jx.star.select,
						mode: 'local',
						triggerAction: 'all',
						valueField: 'value',
						displayField: 'text',
						value: plantypeData[0][0]},
					{xtype:'hidden', fieldLabel:'主要内容与申请理由', name:'money_plan__plan_desc', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'主键', name:'money_change__change_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'调整申请人ID', name:'money_change__change_userid', defaultval:'fun_getUserId()', anchor:'100%'}
				]
			}
			]
		},{
			anchor:'100%',
			border: false,
			layout:'column',
			autoHeight:true,
			items:[{
				border:false,
				columnWidth:0.99,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'textarea', fieldLabel:'调整原因', name:'money_change__change_desc', allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', width:'100%', height:48, maxLength:200},
					{xtype:'textarea', fieldLabel:'备注', name:'money_change__change_memo', width:'100%', height:48, maxLength:200}
				]
			}
			]
		}]
	}];
	
	config.param = {
		items: items,
		funid: 'money_chg'
	};

	config.initpage = function(formNode){
		var event = formNode.event;
		
		var checkval = function(form) {
			var chgtype = form.get('money_change__change_type');
			if (chgtype == '1') return true;
			
			var fdmoney = form.findField('money_change__after_money');
			var plan_money = fdmoney.getValue();
			
			if (plan_money.length == 0 || parseFloat(plan_money) == 0) {
				JxHint.alert('调整后的总投资金额不能为0！');
				fdmoney.focus(true);
				return false;
			}
			
			var ydmoney = form.findField('money_change__after_yearmoney');
			var year_money = ydmoney.getValue();
			if (year_money.length == 0 || parseFloat(year_money) == 0) {
				JxHint.alert('调整后的年度投资金额不能为0！');
				ydmoney.focus(true);
				return false;
			}
			
			if (parseFloat(year_money) > parseFloat(plan_money)) {
				JxHint.alert('调整后的年度投资不能大于总投资！');
				return false;
			}
			return true;
		};
		
		event.on('beforeaudit', function(event) {
			return checkval(event.form);
		});
		
		//扩展保存前事件，如果投资金额为0，则不能保存
		event.on('beforesave', function(event, data) {
			return checkval(event.form);
		});
	};
	
	return new Jxstar.FormNode(config);
}